package com.ktgj.customer.util;

import java.io.IOException;

/**
 * 参数处理工具类
 * <p>
 * <p>
 * 1、解密
 * 2、加密
 * </p>
 *
 * @version 1.0
 * @class_name EncryptUtil
 * @author: Huai Xiao Zi
 * @Date: 2018/4/24
 * @Time: 19:10
 */
public class EncryptUtil {

    /**
     *
     * 1、解密
     *
     * @param dataContext    待解密消息体
     * @param terminalDesKey 密钥
     * @return java.lang.String  明文
     * @author Huai Xiao Zi
     * @Description:
     * @version 1.0
     * @date 2018/5/18 16:47
     */
    public static String decryption(String dataContext, String terminalDesKey) throws IOException {
        return Base64Util.decode(RsaUtil.decryptByPubCerText(dataContext, terminalDesKey));
    }


    /**
     * 2、加密
     *
     * @param result            待加密的结果
     * @param keyCertificatePwd 数字证书密码
     * @param keyCertificate    私钥
     * @return java.lang.String
     * @author Huai Xiao Zi
     * @Description:
     * @version 1.0
     * @date 2018/5/18 16:47
     */
    public static String encrypt(String result, String keyCertificatePwd, byte[] keyCertificate) throws Exception {
        //后台加密:
        // 1、先转UTF-8 bytes 然后再加密成字符串
        // 2、拿base64加密的字符串进行RSA加密，发给商户
        return RsaUtil.encryptByPriPfxStream(Base64Util.encode(result.getBytes("UTF-8")), keyCertificate, keyCertificatePwd);
    }
    private EncryptUtil() {
    }
}
